#include<bits/stdc++.h>
using namespace std;
#define TOP_K_FREQUENT
#ifdef TOP_K_FREQUENT
class Solution {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        unordered_map<int,int>mp;
        vector<int>ret;
        for(auto&e:nums)
            mp[e]++;
        vector<pair<int,int>>v(mp.begin(),mp.end());
        sort(v.begin(),v.end(),[&](pair<int,int>a,pair<int,int>b)
        {
            return a.second>b.second;
        });
        for(auto&e:v)
        {
            if(k--)
                ret.push_back(e.first);
            else return ret;
        }
        return ret;
    }
};
#endif